package com.cookor.poi.common.config;

import org.springframework.web.filter.OncePerRequestFilter;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Description: TODO
 * @author: scott
 * @date: 2021年04月25日 16:54
 */
public class Cros extends OncePerRequestFilter {
    @Override
    protected void doFilterInternal(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, FilterChain filterChain) throws ServletException, IOException {
        // if (request.getHeader("Access-Control-Request-Method") != null &&
        // "OPTIONS".equals(request.getMethod())) {
        // CORS "pre-flight" request
        httpServletResponse.addHeader("Access-Control-Allow-Origin", "*");
        httpServletResponse.addHeader("Access-Control-Allow-Methods",
                "GET, POST, PUT, DELETE");
        httpServletResponse.addHeader("Access-Control-Allow-Headers", "Content-Type");
        httpServletResponse.addHeader("Access-Control-Max-Age", "1800");// 30 min
        // }
        filterChain.doFilter(httpServletRequest, httpServletResponse);

    }
}
